Forum: Ruby on Rails Is it possible with Rails to interact with SVN Server and/or the server's shell?

5a41028798f4e263c2d0692f5b1847ec?d=identicon&s=25 Monserrat Foster (Guest)
on 2013-11-06 14:23
(Received via mailing list)
Hello! I'm fairly new to Ruby and Rails, and currently I don't have any
knowledge on interacting with the server's shell or a SVN server, but
now I
have to develop an app where admins allow/restrict access to files and
folders from the app and some sort of version control of the files is
need
so I thought, to install a SVN server also and from the app allow users
to
access files they've been authorized to. I've been searching about this
but
I can't seem to find a concrete answer. Could some please tell me if
this
is possible and if so, point me in the right direction, what sort of
stuff
should i look into first?

Thank you.
A47e0a6beeb9d048ff054fc1c3a97418?d=identicon&s=25 Walter Davis (walterdavis)
on 2013-11-06 14:55
(Received via mailing list)
On Nov 6, 2013, at 8:21 AM, Monserrat Foster wrote:

> Hello! I'm fairly new to Ruby and Rails, and currently I don't have any
knowledge on interacting with the server's shell or a SVN server, but now I have
to develop an app where admins allow/restrict access to files and folders from 
the
app and some sort of version control of the files is need so I thought, to 
install
a SVN server also and from the app allow users to access files they've been
authorized to. I've been searching about this but I can't seem to find a 
concrete
answer. Could some please tell me if this is possible and if so, point me in the
right direction, what sort of stuff should i look into first?
>
> Thank you.

I built something vaguely similar to this a number of years ago, and
while I didn't go down the SVN path, what I did was this:

1. User authentication with Devise, authorization with CanCan.
2. Files stored with Paperclip (in this case they were all PDF) with
text scraped from each file into a keywords field on the parent model.
3. Files versioned with vestal_version, which provided forward/back in
time navigation. (I did have to hack Paperclip to never delete an
attachment, and to rename each attached file to include the version
info.)

I'm not sure if SVN would have been a saner choice here, I did end up
reinventing the wheel. The benefit for me was that everything was in one
(Rails) mental model, so I didn't have to create a bridge back and forth
between my user management and file management.

Walter
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2013-11-06 15:05
Monserrat Foster wrote in post #1126580:
> Hello! I'm fairly new to Ruby and Rails, and currently I don't have any
> knowledge on interacting with the server's shell or a SVN server, but
> now I
> have to develop an app where admins allow/restrict access to files and
> folders from the app and some sort of version control of the files is
> need
> so I thought, to install a SVN server also and from the app allow users
> to
> access files they've been authorized to. I've been searching about this
> but
> I can't seem to find a concrete answer. Could some please tell me if
> this
> is possible and if so, point me in the right direction, what sort of
> stuff
> should i look into first?

Issuing system commands is as simple as:

system svn <command>

Or when you want to capture the command's standard output into a string:

out = `svn <command>` # These are back tics

And, if you decide to use a SCM as a backed to store your files what not
choose a SCM that isn't a steaming pile of sh*t. Like git
(http://git-scm.com). Just saying...
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2013-11-06 15:07
Robert Walker wrote in post #1126590:
>
> Issuing system commands is as simple as:
>
> system svn <command>

My apologies, but you need to quote the command part:

system 'svn <command>'
5a41028798f4e263c2d0692f5b1847ec?d=identicon&s=25 Monserrat Foster (Guest)
on 2013-11-06 15:20
(Received via mailing list)
Hello all, thanks for replying.

Explaining a little further what I need is to set the permissions to
determined users from the app, however, the files aren't in the same
server
as the app and it should be relatively easy to the users to access the
files, and the admin wants to be able to see what files and exactly what
was modified by that user on that file and when, etc,etc (That's why I
thought of an SVN server or something similar) . My idea was adding the
permissions to a folder via the app so, the user in whatever SVN client
he
has, is able to download the lastest file and modify it and at the same
time, the admin would be able to view who, what and when the files were
modified. The app would only keep a record filled by the user but that
wouldn't be 100% accurate due to users (because they can pretty much
write
whatever they want).

On Wednesday, November 6, 2013 9:37:08 AM UTC-4:30, Ruby-Forum.com User
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2013-11-06 22:40
Monserrat Foster wrote in post #1126594:
> Explaining a little further what I need is to set the permissions to
> determined users from the app, however, the files aren't in the same
> server

Keeping in mind that what I'm about to say is completely off the top of
my head...

Given that your documents are stored on a separate server from the app
thing get a little more tricky. For sake of reference let's call them
"Doc Server" and "App Server".

Assuming you have enough control of the Doc Server that you could
install a service application that's probably the approach I would take.
I would hide all access to the files behind a service application with
some sort of HTTP interface. It would be REST based if I were to build
it returning JSON responses. It would also provide secured access to the
requested files. So we have JSON for the file metadata and HTTP access
to the file data.

The service app would have a multi-part form upload used to receive
incoming files from a user. The service app would need to know the name
and email of the user, the path in the local git working tree along with
the file data.

git add --all

Used to add any new (untracked) files to the git repository.

git commit --author="John Doe <john@example.com>" -m "Changing a test
file."

This would commit all change setting the commit author to "John Doe
<john@example.com>".

git log --author="John Doe <john@exmaple.com>"

This would filter the log output to just John's commits.

git log --author="John Doe <john@exmaple.com>" --name-status

This would also include a list of files changes and the status code for
the type of change.

All of this power would be available to the service application via the
Ruby system command (or back tic):

-------------------------
#!/usr/bin/env ruby
git_user = "John Doe <john@example.com"

out = `git log --no-color --author="#{git_user}" --pretty=full`
puts out
-------------------------

$ ./main.rb
commit 58359794f4443985279cdd1627cdf944fd140d24 (HEAD, master)
Author: John Doe <john@example.com>
Commit: Robert Walker <robert@example.com>

    Changing test file.

M  test.txt

Notice I used --pretty-full in this example to illustrate the difference
in the author vs. the committer of the change. The committer would
always be the service app, or whatever is configured in your git config.
The author is provided by the service application.

Now it's just a matter of writing a Ruby class to parse the git output
and create the JSON metadata that the service application would return
to the application running on the App Server.

Secure the whole this with some sort of basic single sign-on or API
token.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.