]> git.parisson.com Git - telemeta.git/commitdiff
added user authentication in order to edit add move markers
authorriccardo <riccardo@parisson.com>
Tue, 8 Mar 2011 17:52:08 +0000 (18:52 +0100)
committerriccardo <riccardo@parisson.com>
Tue, 8 Mar 2011 17:52:08 +0000 (18:52 +0100)
telemeta/htdocs/js/application.js
telemeta/htdocs/timeside/src/marker.js
telemeta/htdocs/timeside/src/markermap.js
telemeta/htdocs/timeside/src/ruler.js
telemeta/models/media.py
telemeta/models/system.py
telemeta/templates/telemeta_default/mediaitem_detail.html
telemeta/tests/model_tests.py

index 2978e5dce5f882e2dca901e02f8f542d5e1bb47d..0dd92af5c6d32d87fd5064d6a7c8b7354d6c7027 100644 (file)
@@ -24,19 +24,20 @@ function setSelectedMenu(){
         ///if we are at home, the window location href corresponds to window location origin,\r
         //so we select only links whose link points EXACTLY to the origin (home link)\r
         var linkHref = normalize(this.href);\r
+        var elm = jQuery(this); //does not work with $.. conflicts?\r
         if(pageOrigin===pageHref){\r
             if(pageHref == linkHref){\r
-                jQuery(this).addClass('active');\r
+                elm.addClass('active');\r
             }else{\r
-                jQuery(this).removeClass('active');\r
+                elm.removeClass('active');\r
             }\r
         }else{\r
             //here, on the other hand, we select if a link points to a page or super page\r
             //of the current paqge\r
             if(linkHref!=pageOrigin && pageHref.match("^"+linkHref+".*")){\r
-                jQuery(this).addClass('active');\r
+                elm.addClass('active');\r
             }else{\r
-                jQuery(this).removeClass('active');\r
+                elm.removeClass('active');\r
             }\r
         }\r
         \r
index 2a904b73103aecfc7918056dcb55c8b3475d722f..5805dc03269358732f46cf14d53d3a877658d86e 100644 (file)
@@ -20,6 +20,7 @@ TimeSide(function($N, $J) {
 
         initialize: function($super, cfg) {
             $super();
+            //sets the fields required???? see ruler.js createPointer
             this.configure(cfg, {
                 rulerLayout: [null, 'required'],
                 viewer: [null, 'required'],
@@ -27,7 +28,8 @@ TimeSide(function($N, $J) {
                 zIndex: null,
                 className: [null, 'required'],
                 id: null,
-                tooltip: null
+                tooltip: null,
+                canMove: false
             });
             this.cfg.rulerLayout = $J(this.cfg.rulerLayout);
             this.cfg.viewer = $J(this.cfg.viewer);
@@ -36,7 +38,9 @@ TimeSide(function($N, $J) {
             this.width = this.cfg.viewer.width();
             this.painter = new jsGraphics(this.cfg.viewer.get(0));
             this._create();
-            this._observeMouseEvents();
+            if(this.cfg.canMove){
+                this._observeMouseEvents();
+            }
         },
 
         free: function($super) {
@@ -130,7 +134,7 @@ TimeSide(function($N, $J) {
                     labelPixelOffset = this.width - labelWidth;
                 this.label.css({
                     left: Math.round(labelPixelOffset) + 'px'
-                    });
+                });
                 this.position = pixelOffset;
             }
             return this;
@@ -204,7 +208,7 @@ TimeSide(function($N, $J) {
             if (this.mouseDown) {
                 var offset = (evt.pageX - this.cfg.rulerLayout.offset().left);
                 this.move(offset);
-                this.fire('move', {
+                this.fire('move', { //calls move (see above)
                     offset: this.position,
                     finish: false
                 });
index f77b5e3dfb51b0c7a1c6903eb3875a28b0204147..9d857be5317dc025aef2ab5ac36ad283149ed6a9 100644 (file)
@@ -32,6 +32,8 @@ TimeSide(function($N, $J) {
         EDIT_MODE_SAVED:0,
         EDIT_MODE_EDIT_TEXT:1,
         EDIT_MODE_MARKER_MOVED:2,
+        //authentication ,sg
+        AUTHENTICATION_MSG :"You must be logged in and have the permission to edit/add/delete markers",
 
         //function to retreve html elements in the edit div associated with marker:
         getHtmElm: function(marker, elementName){
@@ -223,7 +225,7 @@ TimeSide(function($N, $J) {
             var div = this.divContainer;
             var markerDiv;
             if(div){
-                var indexLabel, descriptionText, offsetLabel, closeButton, okButton, header, editButton, descriptionLabel;
+                var indexLabel, descriptionText, offsetLabel, deleteButton, okButton, header, editButton, descriptionLabel;
                 var margin = '1ex';
 
                 //index label
@@ -238,8 +240,7 @@ TimeSide(function($N, $J) {
                     fontWeight:'bold',
                     display:'inline-block',
                     width:'3ex',
-                    textAlign: 'center'
-                    ,
+                    textAlign: 'center',
                     fontFamily: 'monospace'
                 })
                 .html(insertionIndex+1);
@@ -263,7 +264,7 @@ TimeSide(function($N, $J) {
                 })
 
                 //close button
-                closeButton = $J('<a/>')
+                deleteButton = $J('<a/>')
                 .attr('title','delete marker')
                 .attr('name', this.MHE_DELETE_BUTTON)
                 .attr("href","#")
@@ -277,6 +278,7 @@ TimeSide(function($N, $J) {
                     color:'white'
                 });
 
+                //var bRadius = '4px 4px 4px 4px';
                 //edit button
                 editButton = $J('<a/>')
                 .attr('title','edit marker description')
@@ -287,15 +289,41 @@ TimeSide(function($N, $J) {
                 }))
                 .css({
                     float:'right',
-                    marginRight:margin
+                    marginRight:margin,
                 });
+                //                .append($J('<span/>').html("EDIT").css({
+                //                    fontSize:'70%',
+                //                    fontWeight:'bold',
+                //                    verticalAlign:'top',
+                //                    color:'#000000',
+                //                    textAlign:'center',
+                //                    margin:'0px',
+                //                    /*border:'1px solid red',*/
+                //                    position:'relative',
+                //                    top:'-0.6ex',
+                //                    padding:'0px'
+                //                }))
+                //                .css({
+                //                    float:'right',
+                //                    height:'1.7ex',
+                //                    marginRight:margin,
+                //                    border:'2px solid #333333',
+                //                    '-webkit-border-radius':bRadius,
+                //                    'moz-border-radius': bRadius,
+                //                    'border-radius': bRadius,
+                //                    paddingLeft:'10px',
+                //                    paddingRight:'10px',
+                //                    paddingTop:'0px',
+                //                    paddingBottom:'0px',
+                //                    backgroundColor:'#FFFFF0'
+                //                });
             
                 //add all elements to header:
                 header = $J('<div/>')
                 .append(indexLabel)
                 .append(offsetLabel)
                 .append(descriptionLabel)
-                .append(closeButton)
+                .append(deleteButton)
                 .append(editButton);
 
                 //description text
@@ -343,8 +371,12 @@ TimeSide(function($N, $J) {
                 var editModeEditText = this.EDIT_MODE_EDIT_TEXT;
                 //action for edit
                 editButton.unbind('click').click( function(){
-                    func_fem.apply(klass,[marker,editModeEditText,editButton, descriptionText,
-                        descriptionLabel, okButton]);
+                    if(CURRENT_USER_NAME){
+                        func_fem.apply(klass,[marker,editModeEditText,editButton, descriptionText,
+                            descriptionLabel, okButton]);
+                    }else{
+                        alert(klass.AUTHENTICATION_MSG);
+                    }
                     return false; //avoid scrolling of the page on anchor click
                 });
 
@@ -352,12 +384,16 @@ TimeSide(function($N, $J) {
                 var editModeSaved = this.EDIT_MODE_SAVED;
                 var func_send = this.sendHTTP;
                 okButton.unbind('click').click( function(){
-                    if(marker.desc !== descriptionText.val()){ //strict equality needed. See note below
-                        marker.desc = descriptionText.val();
-                        func_send(marker);
+                    if(CURRENT_USER_NAME){
+                        if(marker.desc !== descriptionText.val()){ //strict equality needed. See note below
+                            marker.desc = descriptionText.val();
+                            func_send(marker);
+                        }
+                        func_fem.apply(klass,[marker,editModeSaved,editButton, descriptionText,
+                            descriptionLabel, okButton]);
+                    }else{
+                        alert(klass.AUTHENTICATION_MSG);
                     }
-                    func_fem.apply(klass,[marker,editModeSaved,editButton, descriptionText,
-                        descriptionLabel, okButton]);
                     return false; //avoid scrolling of the page on anchor click
                 });
 
@@ -365,11 +401,15 @@ TimeSide(function($N, $J) {
                 var remove = this.remove;
                 //reference the class (this) as within the function below this will refer to the document
                 
-                closeButton.unbind('click').click( function(){
-                    remove.apply(klass,[marker]);
+                deleteButton.unbind('click').click( function(){
+                    if(CURRENT_USER_NAME){
+                        remove.apply(klass,[marker]);
+                    }else{
+                        alert(klass.AUTHENTICATION_MSG);
+                    }
                     return false; //avoid scrolling of the page on anchor click
                 });
-
+                
                 //insert the new div created
                 var divLen = div.children().length;
                 div.append(markerDiv);
@@ -385,7 +425,7 @@ TimeSide(function($N, $J) {
 
         //sets the edit mode in the div associated to marker. Last 4 arguments are optional
         fireEditMode: function(marker, editMode, editButton, descriptionText,
-            descriptionLabel, okButton){
+            descriptionLabel, okButton,deleteButton){
             var e = this.getHtmElm;
             if(editButton == undefined){
                 editButton = e(marker,this.MHE_EDIT_BUTTON);
@@ -399,8 +439,17 @@ TimeSide(function($N, $J) {
             if(okButton == undefined){
                 okButton = e(marker,this.MHE_OK_BUTTON);
             }
+            if(deleteButton == undefined){
+                deleteButton = e(marker,this.MHE_DELETE_BUTTON);
+            }
             var speed = 400; //fast is 200 slow is 600 (see jQuery help)
             var klass = this;
+
+            //if user is not authenticated and does not have the necessary permission, we reset editmode to undefined
+            //we treat this case below (last else)
+            if(!(CURRENT_USER_NAME)){
+                editMode = undefined;
+            }
             //var editModeSaved = this.EDIT_MODE_SAVED;
             if(editMode == this.EDIT_MODE_EDIT_TEXT){ //edit text
                 descriptionLabel.hide(); //without arguments, otherwise alignement problems arise (in chrome)
@@ -425,11 +474,17 @@ TimeSide(function($N, $J) {
                 //descriptionText.hide(speed);
                 okButton.show(speed);
             }else{
-                var function_sld = klass.setLabelDescription;
-                editButton.show(speed, function(){
-                    function_sld.apply(klass,[marker]);
+                if(!(CURRENT_USER_NAME)){
+                    editButton.hide();
+                    deleteButton.hide();
                     descriptionLabel.show();
-                });
+                }else{
+                    var function_sld = klass.setLabelDescription;
+                    editButton.show(speed, function(){
+                        function_sld.apply(klass,[marker]);
+                        descriptionLabel.show();
+                    });
+                }
                 descriptionText.hide(speed);
                 okButton.hide(speed);
             }
@@ -437,12 +492,16 @@ TimeSide(function($N, $J) {
 
 
         //sets the length of the label description. Note that all elements must be visible.
-        //Therefore, we call $N.Util.setUpTabs() from controller once all markers have been loaded
+        //Therefore, we call $N.Util.setUpTabs() once all markers have been loaded
         setLabelDescription: function(marker){
             var mDiv = marker.div;
             var e = this.getHtmElm;
             var space = mDiv.width()-e(marker, this.MHE_INDEX_LABEL).outerWidth(true)-e(marker, this.MHE_OFFSET_LABEL).outerWidth(true)-
             e(marker, this.MHE_EDIT_BUTTON).outerWidth(true)-e(marker, this.MHE_DELETE_BUTTON).outerWidth(true);
+            //space is the space available for the label. Decrease it of 20% in order to keep the extra space for
+            //zooming in. This does not assures indefinitely that we won't have overlaps or overflows but gives us
+            //some zoom increase without them. Note: css overflow property does not work
+            space = space - 0.1*space;
             var labelDesc = e(marker, this.MHE_DESCRIPTION_LABEL);
             var str='';
             labelDesc.html(str);
index 59e5bbb14dcc1e212d1f57314f5e9e6af2337e68..de52191b9c4dc23edadc880fa584ddce8967800f 100644 (file)
@@ -38,13 +38,15 @@ TimeSide(function($N, $J) {
             this.waveContainer = this.cfg.viewer.find('.' + $N.cssPrefix + 'image-canvas');
             this._setDuration(this.cfg.soundProvider.getDuration());
             var imgContainer = this.cfg.viewer.find('.' + $N.cssPrefix + 'image-container'); // for IE
-            this._observeMouseEvents(this.waveContainer.add(imgContainer));
-            if (this.cfg.map) {
-                this.cfg.map
-                .observe('add', this.attach(this._onMapAdd))
-                .observe('remove', this.attach(this._onMapRemove))
-                .observe('indexchange', this.attach(this._onMapIndexChange));
-            }
+            
+                this._observeMouseEvents(this.waveContainer.add(imgContainer));
+                if (this.cfg.map) {
+                    this.cfg.map
+                    .observe('add', this.attach(this._onMapAdd))
+                    .observe('remove', this.attach(this._onMapRemove))
+                    .observe('indexchange', this.attach(this._onMapIndexChange));
+                }
+            
             this.cfg.soundProvider.observe('update', this.attach(this._onSoundProviderUpdate));
         },
 
@@ -241,17 +243,18 @@ TimeSide(function($N, $J) {
                 zIndex: 1000,
                 top:0,
                 className: 'pointer',
-                tooltip: 'Move head'
+                tooltip: 'Move head',
+                canMove: true
             });
-//            //create the label
-//            var tsMainLabel = $.find('.' + $N.cssPrefix + 'label');
-//            if(tsMainLabel){
-//                var label = tsMainLabel.find('#' + $N.cssPrefix + 'pointerOffset');
-//                if(!label){
-//                    label = $("<span/>").id('#' + $N.cssPrefix + 'pointerOffset').css('zIndex','10').appendTo(tsMainLabel);
-//                    this.pointer.label = label;
-//                }
-//            }
+            //            //create the label
+            //            var tsMainLabel = $.find('.' + $N.cssPrefix + 'label');
+            //            if(tsMainLabel){
+            //                var label = tsMainLabel.find('#' + $N.cssPrefix + 'pointerOffset');
+            //                if(!label){
+            //                    label = $("<span/>").id('#' + $N.cssPrefix + 'pointerOffset').css('zIndex','10').appendTo(tsMainLabel);
+            //                    this.pointer.label = label;
+            //                }
+            //            }
 
             this.pointer
             //.setText("+")
@@ -335,6 +338,7 @@ TimeSide(function($N, $J) {
         },
 
         _onMouseUp: function(evt) {
+            
             if (this.mouseDown) {
                 this.mouseDown = false;
                 this.fire('move', {
@@ -345,6 +349,9 @@ TimeSide(function($N, $J) {
         },
 
         _observeMouseEvents: function(element) {
+             if(!(CURRENT_USER_NAME)){
+                return;
+            }
             element
             .bind('click dragstart', function() {
                 return false;
@@ -371,9 +378,14 @@ TimeSide(function($N, $J) {
                 fontSize: this.cfg.fontSize,
                 className: 'marker',
                 id: marker.id,
-                tooltip: 'Move marker'
+                tooltip: 'Move marker',
+                canMove: CURRENT_USER_NAME
             });
-            m.observe('move', this.attach(this._onMarkerMove))
+            if(CURRENT_USER_NAME){
+                m.observe('move', this.attach(this._onMarkerMove))
+            }
+            //m.observe('move', this.attach(this._onMarkerMove))
+            m
             .setText(index + 1)
             .move(pixelOffset)
             .show();
@@ -414,7 +426,7 @@ TimeSide(function($N, $J) {
         },
 
         _onDoubleClick: function(evt) {
-            if (this.cfg.map) {
+            if (this.cfg.map && CURRENT_USER_NAME) {
                 var offset = (evt.pageX - this.container.offset().left)
                 / this.width * this.duration;
                 this.fire('markeradd', {
index d1fafeb3cdaf915e80cfc607dd635d6f289f92f0..d10468607fbcee5692ce67bdd78f84a9291db5a2 100644 (file)
@@ -33,6 +33,7 @@
 # Authors: Olivier Guilyardi <olivier@samalyse.com>
 #          David LIPSZYC <davidlipszyc@gmail.com>
 
+from django.contrib.auth.models import User
 from django.utils.translation import ugettext_lazy as _
 from telemeta.models.core import *
 from telemeta.models.enum import ContextKeyword
@@ -346,7 +347,8 @@ class MediaPart(MediaResource):
 
 class Playlist(ModelCore):
     "Item or collection playlist"
-    owner_username = ForeignKey('User', related_name="playlists", db_column="owner_username") 
+    #owner_username = ForeignKey('User', related_name="playlists", db_column="owner_username")
+    owner_username = ForeignKey(User, related_name="playlists", db_column="owner_username")
     name           = CharField(_('name'), required=True)
 
     class Meta(MetaCore):
index b08379a6da85904b7b824a557e5b923e21d0559e..2071fbc67dcef056b278c6d10c2bd3122e409d6d 100644 (file)
 # Authors: Olivier Guilyardi <olivier@samalyse.com>
 #          David LIPSZYC <davidlipszyc@gmail.com>
 
+from django.contrib.auth.models import User
 from telemeta.models.core import *
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils.translation import ugettext_lazy as _
 
 
-class User(ModelCore):
-    "Telemeta user"
-    LEVEL_CHOICES = (('user', 'user'), ('maintainer', 'maintainer'), ('admin', 'admin'))    
-
-    username   = CharField(_('username'), primary_key=True, max_length=64, required=True)
-    level      = CharField(_('level'), choices=LEVEL_CHOICES, max_length=32, required=True)
-    first_name = CharField(_('first name'))
-    last_name  = CharField(_('last name'))
-    phone      = CharField(_('phone'))
-    email      = CharField(_('email'))
-
-    class Meta(MetaCore):
-        db_table = 'users'
-
-    def __unicode__(self):
-        return self.username
+#class User(ModelCore):
+#    "Telemeta user"
+#    LEVEL_CHOICES = (('user', 'user'), ('maintainer', 'maintainer'), ('admin', 'admin'))
+#
+#    username   = CharField(_('username'), primary_key=True, max_length=64, required=True)
+#    level      = CharField(_('level'), choices=LEVEL_CHOICES, max_length=32, required=True)
+#    first_name = CharField(_('first name'))
+#    last_name  = CharField(_('last name'))
+#    phone      = CharField(_('phone'))
+#    email      = CharField(_('email'))
+#
+#    class Meta(MetaCore):
+#        db_table = 'users'
+#
+#    def __unicode__(self):
+#        return self.username
 
 class Revision(ModelCore):
     "Revision made by user"
@@ -64,8 +65,9 @@ class Revision(ModelCore):
     element_id           = IntegerField(_('element identifier'), required=True)
     change_type          = CharField(_('modification type'), choices=CHANGE_TYPE_CHOICES, max_length=16, required=True)
     time                 = DateTimeField(_('time'), auto_now_add=True)
-    user                 = ForeignKey('User', db_column='username', related_name="revisions", verbose_name=_('user'))
-    
+    #user                 = ForeignKey('User', db_column='username', related_name="revisions", verbose_name=_('user'))
+    user                 = ForeignKey(User, db_column='username', related_name="revisions", verbose_name=_('user'))
+
     @classmethod
     def touch(cls, element, user):    
         "Create or update a revision"
index bc84fdd6dc9b2a680ddd475532a8b9faa0f5c931..fd06fad0862f6c7c3b4de6a917d67903867df8b7 100644 (file)
     soundManager.debugMode = false;
     set_player_image_url('{% url telemeta-item-visualize item.public_id,visualizer_id,"WIDTH","HEIGHT" %}');
     load_player({{ item.approx_duration.as_seconds }});
+    
 </script>
+<<<<<<< TREE
+
+{% if user.is_authenticated and perms.telemeta.change_mediaitem %}
+    <script type='text/javascript'>var CURRENT_USER_NAME="{{ user.username }}";</script>
+{% else %}
+    <script type='text/javascript'>var CURRENT_USER_NAME=undefined;</script>
+{% endif %}
+
+    {% endblock %}
+=======
 {% endblock %}
+>>>>>>> MERGE-SOURCE
 
 {% if item %}
 {% block submenu %}
index 8ee69d24616b7ba4cb683a4623f9bc82ee80b74c..ba6de4a49559c726640b060bbc4e1feef035214a 100644 (file)
@@ -33,6 +33,7 @@
 # Authors: Olivier Guilyardi <olivier@samalyse.com>
 #          David LIPSZYC <davidlipszyc@gmail.com>
 
+from django.contrib.auth.models import User
 import unittest
 from telemeta.models import *
 from datetime import datetime, timedelta
@@ -42,8 +43,10 @@ class CollectionItemTestCase(unittest.TestCase):
     def setUp(self):
         "Create a test database based on objects created in Django"
    
-        self.david   = User.objects.create(username="david", level="user")
-        self.olivier = User.objects.create(username="olivier", level="admin")    
+#        self.david   = User.objects.create(username="david", level="user")
+#        self.olivier = User.objects.create(username="olivier", level="admin")
+        self.david   = User.objects.create_user(username="david")
+        self.olivier = User.objects.create_user(username="olivier")
 
         self.country = LocationType.objects.create(code="country", name="Country")
         self.continent = LocationType.objects.create(code="continent", name="Continent")